﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Saker.Kernel.DAL;
using Saker.Kernel.Model;
using Saker.Utility;

namespace Saker.Kernel.BLL
{
    #region SysUser业务逻辑层
    /// <summary>
    ///SysUser业务逻辑层
    /// </summary>
    public partial class SysUserBLL
    {
        #region SysEvent业务逻辑层 自动生成
        /// <summary>
        /// 添加SysUser
        /// </summary>
        /// <param name="SysUser">SysUser实体</param>
        /// <returns>添加后的SysUser实体</returns>
        public SysUser Add(SysUser sysUser)
        {
            return new SysUserDAL().Add(sysUser);
        }
        /// <summary>
        /// 根据主键删除SysUser
        /// </summary>
        /// <param name="UserID">UserID主键</param>
        /// <returns>影响的行数</returns>
        public int DeleteByUserID(int userID)
        {
            return new SysUserDAL().DeleteByUserID(userID);
        }
        /// <summary>
        /// 根据主键更新
        /// </summary>
        /// <param name="SysUser">SysUser实体</param>
        /// <returns>影响的行数</returns>
        public int Update(SysUser sysUser)
        {
            return new SysUserDAL().Update(sysUser);
        }

        /// <summary>
        /// 根据主键得到实体
        /// </summary>
        /// <param name="UserID">UserID主键</param>
        /// <returns>SysUser实体</returns>
        public SysUser GetByUserID(int userID)
        {
            return new SysUserDAL().GetByUserID(userID);
        }
        /// <summary>
        /// 得到总行数
        /// </summary>
        /// <returns>总行数</returns>
        public int GetTotalCount()
        {
            return new SysUserDAL().GetTotalCount();
        }
        /// <summary>
        /// 分页，仅sql 2005及以上版本使用
        /// </summary>
        /// <param name="minrownum">开始行数</param>
        /// <param name="maxrownum">结束行数</param>
        /// <returns>SysUser实体集合</returns>
        public IEnumerable<SysUser> GetPagedData(int minrownum, int maxrownum)
        {
            return new SysUserDAL().GetPagedData(minrownum, maxrownum);
        }
        /// <summary>
        /// 分页，调用存储过程
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="recordCount">记录数</param>
        /// <param name="pageSize">每页记录数</param>
        /// <param name="pageCount">总页数</param>
        /// <param name="whereCondition">where</param>
        /// <returns>DataTable数据集</returns>
        public DataTable GetPagingRecord(int pageIndex, ref int recordCount, int pageSize, ref int pageCount, string whereCondition)
        {
            return new SysUserDAL().GetPagingRecord(pageIndex, ref recordCount, pageSize, ref pageCount, whereCondition);
        }
        /// <summary>
        /// 得到所有SysUser实体集合
        /// </summary>
        /// <returns>SysUser实体集合</returns>
        public IEnumerable<SysUser> GetAll()
        {
            return new SysUserDAL().GetAll();
        }
        #endregion

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="pass">密码</param>
        /// <returns>用户实体</returns>
        public bool UserLogin(string name, string pass)
        {
            SysUser user = new SysUserDAL().UserLogin(name, StringHelper.GetMD5(pass));
            if (user == null)
            {
                return false;
            }
            else
            {
                string sessionname = "SakerAdmin";
                if (System.Web.HttpContext.Current.Session[sessionname] != null)
                {
                    System.Web.HttpContext.Current.Session.Remove(sessionname);
                }
                System.Web.HttpContext.Current.Session.Add(sessionname, user);
                return true;
            }
        }
    }
    #endregion
}
